package com.neusoft.yuejian_6.fragment;


import android.content.Intent;
import android.os.Bundle;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.neusoft.yuejian_6.activity.TrainCainiaoActivity;
import com.neusoft.yuejian_6.activity.TrainJinjieActivity;
import com.neusoft.yuejian_6.activity.TrainRumenActivity;
import com.neusoft.yuejian_6.adapter.TrainAdapter;

import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.javabean.Train;
import com.neusoft.yuejian_6.model.TrainModel;

import java.util.List;
import android.support.v4.app.Fragment;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class TrainFragment  extends Fragment {
    private RecyclerView recyclerView;
    private View view = null;
    private ImageView train_pic;
    //private ImageButton id_search;
    private TextView train_name;
    private RadioButton id_cainiao,id_jinjie,id_rumen;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.tab01, container, false);
        recyclerView = (RecyclerView) view.findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        initView();
        getData();
        initEvents();
        return view;
    }
    private void initView()
    {
        train_name= (TextView) view.findViewById(R.id.train_name);
        train_pic= (ImageView) view.findViewById(R.id.train_pic);
        id_cainiao=(RadioButton)view.findViewById(R.id.id_cainiao);
        id_rumen=(RadioButton)view.findViewById(R.id.id_rumen);
        id_jinjie=(RadioButton)view.findViewById(R.id.id_jinjie);
        //id_search=(ImageButton)view.findViewById(R.id.id_search);

    }


    public void initEvents() {
        id_cainiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1=new Intent();
                intent1.setClass(TrainFragment.this.getActivity(),TrainCainiaoActivity.class);
                startActivity(intent1);

            }
        });

        id_rumen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1=new Intent();
                intent1.setClass(TrainFragment.this.getActivity(),TrainRumenActivity.class);
                startActivity(intent1);

            }
        });

        id_jinjie.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1=new Intent();
                intent1.setClass(TrainFragment.this.getActivity(),TrainJinjieActivity.class);
                startActivity(intent1);

            }
        });

//        id_search.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent1 = new Intent();
//                intent1.setClass(TrainFragment.this.getActivity(), SearchTrainActivity.class);
//                startActivity(intent1);
//
//            }
//        });



    }

    //获取列表数据
    private void getData() {
        TrainModel trainModel=new TrainModel();
        Call<List<Train>> call=trainModel.getTrainlist();
        // System.out.print("t_name");
        call.enqueue(new Callback<List<Train>>() {
            @Override
            public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                List<Train> data = response.body();  //获取数据
                System.out.printf("data");
                recyclerView.setAdapter(new TrainAdapter(TrainFragment.this.getActivity(), data));
            }
            @Override
            public void onFailure(Call<List<Train>> call, Throwable t) {

            }
        });



    }


}



